<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta http-equiv="cache-control" content="cache">
		<title>Play Sound Demo</title>		
		<link href="../css/qs.css" rel="stylesheet" type="text/css"/>
		<link href="../css/ui/button.css" rel="stylesheet" type="text/css"/>
		<link href="../theme/default/style.css" rel="stylesheet" type="text/css"/>
		<style>
		.qs-ui-btn{margin:10px;}
		</style>		
		<script type="text/javascript" src="../lib/jquery.js"></script>
	</head>
	<body oncontextmenu="return false;">
	<a href="#" class="qs-ui-btn">Play Sound</a>
	<script>
	/*Play sound component*/
	/*
	 * profile:    JSON, {src:'chimes.wav',altSrc:'',loop:false}
	 * 
	 * setSrc:     Function, set the source of sound
	 * play:       Function, play sound
	 */
	if (!Util){
		var Util = {};
	}
	Util.soundComponent=function(profile){
		this.profile={
			src:'',　　　　　　　　　  
			altSrc:'',　　　　　　　　 
			loop:false　　　　　　　  
		};
		if(profile) {
			$.extend(this.profile,profile);
		}
		this.soundObj=null;
		this.isIE = !-[1,];　
		this.init();
	};
	Util.soundComponent.prototype={
		init:function(){
			this._setSrc();
		},        
		_setSrc:function(){
			if(this.soundObj){                
				if(this.isIE){
					this.soundObj[0].src=this.profile.src;    
				}else{
					this.soundObj[0].innerHTML='<source src="'+this.profile.src+'" /><source src="'+this.profile.altSrc+'" />';    
				}    
			}else{
				if(this.isIE){
					this.soundObj=$('<bgsound volume="-10000" loop="1" src="'+this.profile.src+'">').appendTo('body');
				}else{
					this.soundObj=$('<audio preload="auto" autobuffer><source src="'+this.profile.src+'" /><source src="'+this.profile.altSrc+'" /></audio>').appendTo('body');
				}                
			}            
		},
		setSrc:function(src,altSrc){
			this.profile.src=src;
			if(typeof altSrc!='undefined'){
				this.profile.altSrc=altSrc;
			}        
			this._setSrc();
		},
		play:function(){
			if(this.soundObj){
				if(this.isIE){
					this.soundObj[0].volume = 1;
					this.soundObj[0].src = this.profile.src;
				}else{
					this.soundObj[0].play();
				}
			}
		}
	};
	var sd=new Util.soundComponent({src:'ding.wav',altSrc:'ding.mp3'});
	$('.qs-ui-btn').bind('click',function(e){
		sd.play();
	}); 
	</script>
	</body>
</html>